/*###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############*/

var IUsers_Admin = {
    setDelGroup : function(newId, delSel){
        var key = AntzBase.dom_dropMenuSelectionKey(delSel);
        if(key == '0') document.getElementById(newId).disabled = 'disabled';
        else if(document.getElementById(newId).disabled == true) document.getElementById(newId).disabled = false;

    },
    new_addGroup : function(fieldId, selObj){
        var key = AntzBase.dom_dropMenuSelectionKey(selObj);
        if(key*1 == 0) return;
        if(document.getElementById(fieldId).value.match(key)){
            // going to remove a group from the list
            if(key!='public'){
                document.getElementById(fieldId).value = document.getElementById(fieldId).value.replace(key, '');
            }else{
                if(confirm('??? Are you sure you want to prevent new members from seeing public pages ???')){
                    document.getElementById(fieldId).value = document.getElementById(fieldId).value.replace(key, '');
                };
            };
        }else{
            // adding a group to the list
            if(document.getElementById(fieldId).value == '') document.getElementById(fieldId).value = key;
            else document.getElementById(fieldId).value = document.getElementById(fieldId).value+','+key;
        };
        // make sure we don't have a comma at the start and end of the list
        if(document.getElementById(fieldId).value.substring(0, 1) == ',')
            document.getElementById(fieldId).value = document.getElementById(fieldId).value.substring(1);
        if(document.getElementById(fieldId).value.substring((document.getElementById(fieldId).value.length-1))==',')
            document.getElementById(fieldId).value = document.getElementById(fieldId).value.substring(0, document.getElementById(fieldId).value.length-1);
        // warn them that having no groups cannot be done
        if(document.getElementById(fieldId).value == '') alert('Users must belong to at least one group');

    }
}

function showErrorMsg(msg, rootUrl){
    var cont = document.getElementById('MainContent');
    var pCont = document.getElementsByClassName('pagecontainer');
    pCont = pCont[0];
    var objs = document.getElementsByClassName('navt_menu');
    var navt = objs[0];
    var div = document.createElement('div');
    var div2 = document.createElement('div');
    var img = document.createElement('img');
    var span = document.createElement('span');
    span.innerHTML = ' '+msg;
    img.src = rootUrl+'/admin/themes/default/images/icons/system/stop.gif';
    img.alt = 'Error';
    img.title = 'Error';
    img.className = 'systemicon';
    div.className = 'pageerrorcontainer';
    div.id = 'errorMsg';
    div2.className = 'pageoverflow';
    div2.appendChild(img);
    div2.appendChild(span);
    div.appendChild(div2);
    appendAfter(navt, div);
}

function showSuccessMsg(msg, rootUrl){

    var cont = document.getElementById('MainContent');
    var pCont = document.getElementsByClassName('pagecontainer');
    pCont = pCont[0];
    var objs = document.getElementsByClassName('navt_menu');
    var navt = objs[0];
    var div = document.createElement('div');
    var p = document.createElement('p');
    var img = document.createElement('img');
    var span = document.createElement('span');
    span.innerHTML = ' '+msg;
    img.src = rootUrl+'/admin/themes/default/images/icons/system/accept.gif';
    img.alt = 'Success';
    img.title = 'Success';
    img.className = 'systemicon';
    div.className = 'pagemcontainer';
    div.id = 'successMsg';
    p.className = 'pagemessage';
    p.appendChild(img);
    p.appendChild(span);
    div.appendChild(p);
    appendAfter(navt, div);
}
// function derived from http://book.itzero.com/read/others/McGraw.Hill.Osborne.JavaScript.2.0.The.Complete.Reference.Second.Edition.eBook-LiB_html/8166final/LiB0073.html
function appendAfter(existingNode, newNode)
{
 if (existingNode.parentNode)
  {
    if (existingNode.nextSibling)
       existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
    else
       existingNode.parentNode.appendChild(newNode);
  }
}
